//#ifndef ACUAS_C
//#define ACUAS_C
// ACUAS Microcontroller Board Easy Programming. ATmega16 or ATmega 32


/// @defgroup ACUAS_C ACUAS Functions
/// @{

/// @file ACUAS.c

#include <ACUAS.h>

void set_seed(void)
//source: http://www.roboternetz.de/wissen/index.php/Zufallszahlen_mit_avr-gcc
{
#ifndef SIMULATION
	unsigned short seed = 0, *p = (unsigned short*) (RAMEND+1);
	extern unsigned short __heap_start;
	while (p >= &__heap_start + 1)
		seed ^= * (--p);
	srandom((unsigned long) seed);
#else
	srandom((unsigned long) 1);
#endif
}

/// Initialize the ports of the controller:
void InitBoard(void)
{
/// Input: buttons at port A
	DDRA  = 0b00000000;
/// switch on pull up resistors
	PORTA = 0b11111111;
/// no button pressed
	PINA = 0b11111111;
/// Output: LEDs at port C
	DDRC  = 0b11111111;
/// switch off all LEDs
	PORTC = 0b11111111;
/// initialize the random number generator
    set_seed();
}

// Wait ds tenth of a second
void delay_ds(unsigned char ds)
{
#ifndef SIMULATION
	uint16_t i, lim= 10*ds;
	for(i=0; i<lim; i++)
	{
		uint16_t __ticks = F_CPU / 400;
		__asm__ volatile (
			"1: sbiw %0,1" "\n\t"
			"brne 1b"
			: "=w" (__ticks)
			: "0" (__ticks)
		);
	}
#endif
}















/// @}
//#endif // ACUAS_C
